package io.renren.modules.sq.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.sq.dao.SqSystemDao;
import io.renren.modules.sq.entity.SqSystemEntity;
import io.renren.modules.sq.service.SqSystemService;
import org.springframework.util.StringUtils;


@Service("sqSystemService")
public class SqSystemServiceImpl extends ServiceImpl<SqSystemDao, SqSystemEntity> implements SqSystemService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SqSystemEntity> page = this.page(
                new Query<SqSystemEntity>().getPage(params),
                new QueryWrapper<SqSystemEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public Page<SqSystemEntity> getSysList(Map<String, Object> params) {
        Page<SqSystemEntity> page = new PageUtils<SqSystemEntity>().getPageByParams(params);
        QueryWrapper<SqSystemEntity> queryWrapper = new QueryWrapper<>();
        String systemName = (String) params.get("systemName"); // 系统名称
        String systemEdition = (String) params.get("systemEdition"); // 系统版本
        String systemDescription = (String) params.get("systemDescription"); // 描述
        String allow = (String) params.get("allow"); // 允许生成授权码0：禁止1：允许
        if(StringUtils.hasText(systemName)) {
            queryWrapper.like("system_name", systemName);
        }
        if(StringUtils.hasText(systemEdition)) {
            queryWrapper.like("system_edition", systemEdition);
        }
        if(StringUtils.hasText(systemDescription)) {
            queryWrapper.like("system_description", systemDescription);
        }
        if(StringUtils.hasText(allow)) {
            queryWrapper.eq("allow", allow);
        }
        baseMapper.selectPage(page, queryWrapper);
        return page;
    }

    @Override
    public List<SqSystemEntity> getUserSystemListByUserid(Long userId) {
        return this.baseMapper.getUserSystemListByUserid(userId);
    }

    @Override
    public List<SqSystemEntity> listbyuserid(String userId,int roleId) {
        return this.baseMapper.listbyuserid(userId,roleId);
    }

    @Override
    public List<SqSystemEntity> getSystemList() {
        return this.baseMapper.getSystemList();
    }

    @Override
    public List<SqSystemEntity> selectListByRoleid(Long roleId) {
        return this.baseMapper.selectListByRoleid(roleId);
    }

    @Override
    public List<SqSystemEntity> listbyroleid(int roleId) {
        return this.baseMapper.listbyroleid(roleId);
    }

}
